class ObjectAndResourceClass < ActiveRecord::Base
  has_and_belongs_to_many :enters_to,  :class_name => "BusinessProcess", :join_table => :enters
  has_and_belongs_to_many :exits_from, :class_name => "BusinessProcess", :join_table => :exits
  
  acts_as_ordered_tree
  
  def distribution=(distribution)
    self[:distribution] = distribution
    
    # Передать всем последователям вариант распределения
    self.descendants.each do |d|
      d.update_attribute 'distribution', distribution
    end
  end
  
  def sc=(array_of_sub_classes)
    sub_classes_string = '0000'
    # [1..4].each do |index|
    #   sub_classes_string[index] = '1' if array_of_sub_classes.include?("#{index}")
    # end
    sub_classes_string[0] = '1' if array_of_sub_classes.include?('0')
    sub_classes_string[1] = '1' if array_of_sub_classes.include?('1')
    sub_classes_string[2] = '1' if array_of_sub_classes.include?('2')
    sub_classes_string[3] = '1' if array_of_sub_classes.include?('3')
    self.sub_classes = sub_classes_string
  end
end
